<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:infConverters="clr-namespace:StockTraderRI.Infrastructure.Converters;assembly=StockTraderRI.Infrastructure"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:inf="clr-namespace:StockTraderRI.Infrastructure;assembly=StockTraderRI.Infrastructure" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="StockTraderRI.Modules.Position.Orders.OrderDetailsView"
    mc:Ignorable="d" d:DesignWidth="964" d:DesignHeight="100.108" Margin="0,0,0,0" AutomationProperties.AutomationId="PositionBuySellTab" >
    <UserControl.Resources>
        <infConverters:EnumToBooleanConverter x:Key="enumToBooleanConverter" />
        <infConverters:StringToNullableNumberConverter x:Key="stringToNullableNumberConverter" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="55" />
            <RowDefinition Height="45" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="130" />
            <ColumnDefinition Width="80" />
            <ColumnDefinition Width="130" />
            <ColumnDefinition Width="80" />
            <ColumnDefinition Width="Auto" MinWidth="321" />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Row="0" Grid.ColumnSpan="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
            <RadioButton Content="Buy" AutomationProperties.AutomationId="BuyRadioButton" Background="{x:Null}" BorderBrush="{x:Null}" Height="Auto" Width="Auto" Margin="0,0,15,0" HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="{Binding Converter={StaticResource enumToBooleanConverter}, ConverterParameter=Buy, Mode=TwoWay, Path=TransactionType}" Style="{StaticResource CustomRadioCheckbox}" Foreground="#FF444444"/>
            <RadioButton Content="Sell" AutomationProperties.AutomationId="SellRadioButton" Background="{x:Null}" BorderBrush="{x:Null}" Height="Auto" Width="Auto" Margin="15,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="{Binding Converter={StaticResource enumToBooleanConverter}, ConverterParameter=Sell, Mode=TwoWay, Path=TransactionType}"  Style="{StaticResource CustomRadioCheckbox}" Foreground="#FF444444"/>
        </StackPanel>

        <TextBlock Grid.Row="0" Grid.Column="2" Text="Shares:" Foreground="#FF444444" VerticalAlignment="Center" Width="Auto" Height="Auto" HorizontalAlignment="Right" Grid.ColumnSpan="1" Margin="0,0,0,0" />
        <!-- NOTE: The following is using validation based on model binding exceptions, using the help 
                   of attached properties to avoid using code-behind. There might be better ways of doing
                   this and it should not be taken as guidance on how to perform validation. -->
        <TextBox Grid.Row="0" Grid.Column="3" AutomationProperties.AutomationId="SharesTextBox" inf:OnValidationError.ShowToolTip="True" inf:OnValidationError.ToggleBackground="Red" Text="{Binding Converter={StaticResource stringToNullableNumberConverter}, Mode=TwoWay, NotifyOnValidationError=True, Path=Shares, ValidatesOnExceptions=True}" HorizontalAlignment="Stretch" Width="120" Height="Auto" VerticalAlignment="Center" Margin="0,0,0,0" Style="{StaticResource CustomTextBox}" />

        <TextBlock Grid.Row="0" Grid.Column="4" Text="Price Limit:" Foreground="#FF444444" HorizontalAlignment="Right" VerticalAlignment="Center" Width="Auto" Height="Auto" Margin="0,0,0,0" />
        <TextBox Grid.Row="0" Grid.Column="5" HorizontalAlignment="Left" Width="120" Height="Auto" VerticalAlignment="Center" Margin="5,0,0,0" inf:OnValidationError.ShowToolTip="True" inf:OnValidationError.ToggleBackground="Red" Text="{Binding Converter={StaticResource stringToNullableNumberConverter}, Mode=TwoWay, NotifyOnValidationError=True, Path=StopLimitPrice, ValidatesOnExceptions=True}" AutomationProperties.AutomationId="PriceLimitTextBox" Style="{StaticResource CustomTextBox}" />

        <TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Width="Auto" Height="Auto" Text="Order Type:" Foreground="#FF444444" VerticalAlignment="Center" />
        <ComboBox   Style="{StaticResource CustomComboBox}"  Grid.Row="1" Grid.Column="1" AutomationProperties.AutomationId="OrderTypeComboBox" Width="120" Height="Auto" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,0,0,0" ItemsSource="{Binding Path=AvailableOrderTypes}" inf:SelectorExtensions.SelectedValue="{Binding Mode=TwoWay, Path=OrderType}" inf:SelectorExtensions.SelectedValuePath="Value" />

        <TextBlock Grid.Row="1" Grid.Column="2" Text="Term:" Foreground="#FF444444" HorizontalAlignment="Right" VerticalAlignment="Center" Width="Auto" Height="Auto" Margin="0,0,0,0" />
        <ComboBox   Style="{StaticResource CustomComboBox}" AutomationProperties.AutomationId="TermComboBox" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Stretch" Width="120" Height="Auto" VerticalAlignment="Center" Margin="0,0,0,0" ItemsSource="{Binding Path=AvailableTimesInForce}" inf:SelectorExtensions.SelectedValue="{Binding Mode=TwoWay, Path=TimeInForce}" inf:SelectorExtensions.SelectedValuePath="Value" />
    </Grid>
</UserControl>
